﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace ZLDC.Common.Estate
{
    public class _Convert
    {
        public static long ToInt64(string Value)
        {
            return ToInt64(Value, 0);
        }

        public static long ToInt64(string Value, long DefaultValue)
        {
            long Result = DefaultValue;

            try
            {
                Result = Convert.ToInt64(Value);
            }
            catch { }

            return Result;
        }

        public static int ToInt(string Value)
        {
            return ToInt(Value, 0);
        }

        public static int ToInt(string Value, int DefaultValue)
        {
            int Result = DefaultValue;

            try
            {
                Result = Convert.ToInt32(Value);
            }
            catch { }

            return Result;
        }

        public static float ToFloat(string Value)
        {
            return ToFloat(Value, 0);
        }

        public static float ToFloat(string Value, float DefaultValue)
        {
            float Result = DefaultValue;

            try
            {
                Result = Convert.ToSingle(Value);
            }
            catch { }

            return Result;
        }

        public static double ToDouble(string Value)
        {
            return ToDouble(Value, 0);
        }

        public static double ToDouble(string Value, double DefaultValue)
        {
            double Result = DefaultValue;

            try
            {
                Result = Convert.ToDouble(Value);
            }
            catch { }

            return Result;
        }

        public static DateTime ToDateTime(string Value)
        {
            return ToDateTime(Value, DateTime.Now);
        }

        public static DateTime ToDateTime(string Value, DateTime DefaultValue)
        {
            DateTime now = DateTime.Now;
            if (DateTime.TryParse(Value, out now))
            {
                return now;
            }
            return DefaultValue;
        }

        public static decimal ToDecimal(string Value)
        {
            return ToDecimal(Value, 0M);
        }

        public static decimal ToDecimal(string Value, decimal defvalue)
        {
            decimal result = 0M;
            if (decimal.TryParse(Value, out result))
            {
                return result;
            }
            return defvalue;
        }

        public static bool ToBool(string Value)
        {
            return ToBool(Value, false);
        }

        public static bool ToBool(string Value, bool DefaultValue)
        {
            bool Result = DefaultValue;

            try
            {
                Result = Convert.ToBoolean(Value);
            }
            catch { }

            return Result;
        }

    }
}
